package com.cj.td.common.util.ini;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;

public class IniReaderNoSection {
	public Properties properties = null;
	/**
	 * 读取asset文件
	 * @param context
	 * @param iniPath
	 */
	public IniReaderNoSection(Context context,String iniPath){
		try{
			InputStream inputStream = context.getResources().getAssets().open(iniPath);
			properties = new Properties();
			properties.load(inputStream);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
	}
	/***
	 * 读取raw文件下的ini文件
	 * @param context
	 * @param resourceId
	 */
	public IniReaderNoSection(Context context, int resourceId) {
		InputStream inputStream = context.getResources().openRawResource(
				resourceId);
		try {
			properties = new Properties();
			properties.load(inputStream);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	/**
	 * 读取sd卡文件
	 * @param filename
	 */
	public IniReaderNoSection(String filename) {
		File file = new File(filename);
		try {
			properties = new Properties();
			properties.load(new FileInputStream(file));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	/**
	 * 获取某个key的值
	 * @param key
	 * @return
	 */
	public String getIniKey(String key){
		if(!properties.contains(key)){
			return null;
		}
		return String.valueOf(properties.get(key));
	}
}
